package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingLevelServiceImpl
 * @Author baohua
 * @Date 2024-07-08
 */

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> getAll() {
        List<NursingLevelVo> nursingLevelVoList = nursingLevelMapper.select();
        return nursingLevelVoList;
    }

    @Override
    public void add(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public PageResponse<NursingLevelVo> listByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        // 初始化分页插件，用于自动处理分页逻辑。
        PageHelper.startPage(pageNum, pageSize);
        // 执行分页查询，返回查询结果的Page对象。
        Page<NursingLevelVo> page = nursingLevelMapper.selectByPage(name, status);
        // 创建分页响应对象，并设置查询结果。
        PageResponse<NursingLevelVo> pageResponse = new PageResponse<>(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    @Override
    public NursingLevelVo getById(long id) {
        NursingLevel nursingLevel = nursingLevelMapper.selectById(id);
        return BeanUtil.toBean(nursingLevel, NursingLevelVo.class);
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void deleteById(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void modifyStatus(Long id, Integer status) {
        nursingLevelMapper.modifyStatus(id, status);
    }
}
